/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.activity;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.services.front.activity.ActivityService;
import shop.services.front.activity.bean.Activity;
import shop.services.front.activityjoin.ActivityjoinService;
import shop.services.front.activityjoin.bean.Activityjoin;
import shop.services.manage.system.bean.User;
import shop.services.manage.system.impl.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**   
 * @类名称：ActivityController
 * @创建人：Wzl
 * @创建时间：2018-01-03 下午16:07:18      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/front/activity/")
public class ActivityController extends FrontBaseController<Activity> {
    private final  static  String ACTIVITY_ISJOIN_YES="y";
    private final  static  String ACTIVITY_ISJOIN_NO="n";
    @Resource
    private ActivityService activityService;
    @Resource
    private ActivityjoinService activityjoinService;
    @Resource
    private UserService userService;
    @Override
    public Services<Activity> getService() {
        return activityService;
    }

    /**
     * 跳转到文章列表页面
     *
     * @return
     */
    @RequestMapping("toArtcleList")
    public String toArtcleList() {
        return "/front/activity/artcle";
    }
    /**
     * 跳转到活动列表页面
     *
     * @return
     */
    @RequestMapping("toActivityList")
    public String toActivityList() {
        return "/front/activity/activityList";
    }

    /**
     * 跳转到活动详情页面
     *
     * @return
     */
    @RequestMapping("toActivityDetail")
    public String toActivityDetail() {
        return "/front/activity/activityDetail";
    }

    /**
     * 跳转到活动照片页面
     *
     * @return
     */
    @RequestMapping("toActivityPicture")
    public String toActivityPicture() {
        return "/front/activity/activityPic";
    }

    /**
     * 跳转到上传照片页面
     *
     * @return
     */
    @RequestMapping("toAddPicture")
    public String toAddPicture() {
        return "/front/activity/uploadPic";
    }

    /**
     * 查询活动列表
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectActivityList")
    @ResponseBody
    public JSONResult selectActivityList(Activity activity){
        List<Activity> activityList = activityService.selectActivityList(activity);
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(activityList);
        return jsonResult;
    }
    /**
     * 查询活动详情
     * @param activity
     * @return
     */
    @RequestMapping(value = "selectActivityDetail")
    @ResponseBody
    public JSONResult selectActivityDetail(HttpSession session, Activity activity) {
        User user=(User)session.getAttribute("userInfo");
        Activityjoin activityjoin=new Activityjoin();
        activityjoin.setUserID(user.getId());
        activityjoin.setActivityID(activity.getId());
        activityjoin=activityjoinService.selectOne(activityjoin);
        activity =  activityService.selectOne(activity);
        if(activityjoin!=null){
            activity.setIsJoin(ACTIVITY_ISJOIN_YES);
        }else{
            activity.setIsJoin(ACTIVITY_ISJOIN_NO);
        }
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(activity);
        return jsonResult;
    }

    @Override
    public JSONResult insertJson(HttpServletRequest request, Activity activity) throws Exception {
        return null;
    }

    @Override
    public JSONResult deleteJson(HttpServletRequest request, Activity activity) throws Exception {
        return null;
    }
}
